package com.dataStructure.leetcode.链表;

/**
 * https://leetcode-cn.com/problems/linked-list-cycle/
 * 快慢指针思想
 */
public class 判断一个链表是否有环 {


    public boolean hasCycle(ListNode head){
        if (head == null || head.next==null)return false;
            ListNode slow = head;
            ListNode fast = head.next;
            while (fast!=null&&fast.next!=null){
                if (fast==slow)return  true;
                    slow = slow.next;
                    fast = fast.next.next;
            }
            return false;
    }
}
